package com.aprivate.kn.ratingsystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.aprivate.kn.ratingsystem.R;
import com.aprivate.kn.ratingsystem.bean.QuestionListBean;

import java.util.List;

/**
 * Created by zhangshaokun on 2018/12/16.
 */

public class QuestionAdapter extends android.widget.BaseAdapter {
    private Context mContext;
    private List<QuestionListBean> mData;

    public QuestionAdapter(Context context, List<QuestionListBean> data) {
        this.mContext = context;
        this.mData = data;
    }

    @Override
    public int getCount() {
        return mData == null ? 0 : mData.size();
    }

    @Override
    public QuestionListBean getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(mContext).inflate(R.layout.item_question, null);
            viewHolder.mQuestionText = view.findViewById(R.id.text_question_name);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        if (null != getItem(i)) {
//            viewHolder.mQuestionText.setText((i + 1) + "、" + getItem(i).getTopics().getTopicName());
            QuestionListBean item = getItem(i);
            viewHolder.mQuestionText.setText((getItem(i).getQuestionPosition() + 1) + "题");
        } else {
            viewHolder.mQuestionText.setText((i + 1) + "题");
        }
        return view;
    }

    static class ViewHolder {
        TextView mQuestionText;
    }
}
